<template>
    <div class="MyAddress">
        <header>
            <span @click="GoBack()"><van-icon name="arrow-left" /></span>
            <p>管理收货地址</p>
            <span></span>
        </header>
        <section>
            <ul>
                <li v-for="(item,index) in addressList" :key="index" v-if="addressList.length>0">
                    <div class="leftAddress">
                        <p><span>{{item.name}}</span><span>{{item.cellphone}}</span></p>
                        <p>
                            <span class="moren">{{item.isdefault == 1?'[默认]':''}}</span>
                            <span>{{item.province}}{{item.city}}{{item.area}}{{item.address}}</span>
                        </p>
                    </div>
                    <span class="rightAddress"><van-icon name="arrow" /></span>
                </li>
            </ul>
        </section>
        <footer>
            <button @click="add()">+添加新收货地址</button>
        </footer>
    </div>
</template>
<script>
    import {getUserAddress} from "../../api/list/list";

    export default {
        name:"myAddress",
        data(){
            return{
                addressList:[]
            }
        },
        created() {
            const params = {
                uid : this.$route.query.uid,
                token:'1ec949a15fb709370f'
            }
            getUserAddress(params).then((res)=>{
                console.log(res)
                if(res.data.data =='没有数据'){
                    this.addressList = []
                }else{
                    this.addressList = res.data.data
                }
            })
        },
        methods:{
            GoBack(){
                history.go(-1)
            },
            add(){
                this.$router.push({path:'/addAddress',query:{uid : this.$route.query.uid}})
            }
        }
    }
</script>
<style lang="less" scoped>
    .MyAddress{
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        header{
            width: 100%;
            height: 1rem;
            display: flex;
            border-bottom: 1px solid #efefef;
            span{
                width: 1rem;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 0.4rem;
            }
            p{
                flex: 1;
                text-align: center;
                line-height: 1rem;
                font-size: 0.32rem;
            }
        }
        section{
            flex: 1;
            overflow: auto;
            ul{
                width: 100%;
                li{
                    width: 100%;
                    height: 1.2rem;
                    border-bottom: 1px solid #efefef;
                    display: flex;
                    padding: 0.1rem 0.1rem;
                    box-sizing: border-box;
                    .leftAddress{
                        flex: 1;
                        p:first-child{
                            width: 100%;
                            span:last-child{
                                padding-left: 0.3rem;
                                box-sizing: border-box;
                            }
                        }
                        p:last-child{
                            width: 3.4rem;
                            .moren{
                                color: #FDB709;
                            }
                            span:last-child{
                                color: #999999;
                                font-size: 0.2rem;
                            }
                        }
                    }
                    .rightAddress{
                        width: 0.8rem;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        i{
                            font-size: 0.3rem;
                            color: #323232;
                        }
                    }
                }
            }
        }
        footer{
            width: 100%;
            height: 1rem;
            padding: 0.2rem 0.3rem;
            box-sizing: border-box;
            border-top: 1px solid #efefef;
            button{
                width: 100%;
                height: 100%;
                background: #EB1625;
                color: white;
                border: none;
                border-radius: 3px;
            }
        }
    }
</style>